//
//  WiiEditTaskTableViewCell.m
//  iFeller
//
//  Created by Wii on 15/12/11.
//  Copyright © 2015年 Wii. All rights reserved.
//

#import "WiiTaskDetailTableViewCell.h"

typedef NS_ENUM (NSInteger,WiiEditTaskCell){
    WiiEditTaskCellIcon = 0 ,
    WiiEditTaskCellTags ,
    WiiEditTaskCellDate ,
    WiiEditTaskCellRepeat ,
    WiiEditTaskCellNoet
};

@interface WiiTaskDetailTableViewCell ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contentLabelHeight;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *contenLabelWidth;

@end
@implementation WiiTaskDetailTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)getCellDataWithDataSource:(NSArray *)dataSource IndexPath:(NSIndexPath *)indexPath{
    self.contenLabelWidth.constant = SCREEN_WIDTH - 74;
    switch ([indexPath section]) {
        case WiiEditTaskCellIcon: {
            switch (self.taskStatus) {
                case 0:
                    self.iconView.image = [UIImage imageNamed:@"iconfont-naozhong"];
                    break;
                case 1:
                    self.iconView.image = [UIImage imageNamed:@"iconfont-ttpodicon"];
                    break;
                case 2:
                    self.iconView.image = [UIImage imageNamed:@"iconfont-finish"];
                    break;
                default:
                    break;
            }
            self.infoLabel.text = dataSource[WiiTaskDataSourceWithName];
        }
            break;
        case WiiEditTaskCellDate:
            if (self.taskStatus == 1) {
                self.infoLabel.text = dataSource[WiiTaskDataSourceWithDate];
            }
            self.infoLabel.text = [self getLocalDate:dataSource[WiiTaskDataSourceWithFinish]];
            self.iconView.image = [UIImage imageNamed:@"Date"];
            break;
        case WiiEditTaskCellTags:
            self.iconView.image = [UIImage imageNamed:@"tag"];
            self.infoLabel.text = dataSource[WiiTaskDataSourceWithTags];
            break;
        case WiiEditTaskCellRepeat:
            self.iconView.image = [UIImage imageNamed:@"repeat"];
            self.infoLabel.text = dataSource[WiiTaskDataSourceWithRepeat];
            break;
        case WiiEditTaskCellNoet:{
            self.iconView.image = IMAGENAMED(@"note");
            NSString *str = dataSource[WiiTaskDataSourceWithNotes];
            CGSize size = [str getSizeWithFont:[UIFont systemFontOfSize:15] forWidth: SCREEN_WIDTH - 50];
            self.contentLabelHeight.constant = size.height + 20;
            self.infoLabel.font = [UIFont systemFontOfSize:15];
            self.infoLabel.text = dataSource[WiiTaskDataSourceWithNotes];
        }
            break;
        default:
            break;
    }
}

//获取本地时间 //显示完成，闹钟时间调用方法
- (NSString *)getLocalDate:(NSString *)date {
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss +0000"];
    NSTimeZone *localZone = [NSTimeZone localTimeZone];
    NSInteger interval = [localZone secondsFromGMTForDate:[formatter dateFromString:date]];
    NSDate *mydate = [[formatter dateFromString:date] dateByAddingTimeInterval:interval];
    [formatter setDateFormat:@"yyyy年MM月dd日 HH:mm"];
    NSString *string = [formatter stringFromDate:mydate];
    return string;
}

@end
